<?php
/*
 * 手机客户端 收藏和取消收藏接口
 * 传入参数 
 * 2013-12-26
 */
include "inc/public_header.php";
include "func/user.php";				//用户信息处理函数
					
//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid 			= $uInfoArr["uid"];				//用户信息主键
 
$zpid			= $_REQUEST["worksid"]; 			//作品主键

$reJson = array();//构建返回值

if(!isset($zpid) || $zpid==""){
	echo json_encode(array("success"=>"0","msg"=>"没有获取到作品主键"));
	die;
}

//判断是不是自己的作品
$sql="SELECT uid from new_weituo_zuopin WHERE id='".$zpid."'";
$db->query($sql);
$db->next_record();
$zpuid= $db->f("uid");
if($uid==$zpuid){
	echo json_encode(array("success"=>"0","errCode"=>"2","msg"=>"不能收藏自己的作品"));
	die;
}

//查询是否存在关注作品记录
$sql = "select id from new_weituo_gz where uid='".$uid."' and zpid='".$zpid."'";
$db->query($sql);
if($db->next_record()){
	//取消关注
	$type = "2";
	$sql = "delete from new_weituo_gz where id='".$db->f("id")."'";
}else{
	//新增关注
	$type = "1";
	$sql = "insert into new_weituo_gz (uid,zpid,ctime) values('".$uid."','".$zpid."',now())";
}
$db->query($sql);

//作品总共被收藏了多少次
$sql = "select count(0) as ct from new_weituo_gz where zpid='".$zpid."'";
$db->query($sql);
$db->next_record();
$zpGzCount = $db->f("ct");

echo json_encode(array(
						 "success"			=>	"1"
						,"worksid"			=>	$zpid		//作品主键
						,"type"				=>	$type		//操作类型，1新增关注  2取消关注
						,"collectionCount"	=>	$zpGzCount	//作品被收藏了多少次
						));		
?>